Ext.define("MyApp.store.LocalAppointments", {

	extend:	"Ext.data.Store",
	requires: ["MyApp.model.Appointments"],
	
	config: {
		storeId: 'LocalAppointments',
		model: "MyApp.model.Appointments",
		//autoLoad: true,
		sorters: [{
			sorterFn: function(record1, record2) {
			
				var s1 = record1.data.starttime;
				var s2 = record2.data.starttime;

                return (record1.data.starttime < record2.data.starttime ) ? 1 : (record1.data.starttime  === record2.data.starttime  ? 0 : -1);
            },
            direction: 'DESC'
		}],
		filters:[
			{filterFn: function(record) { 
			var today = new Date();
			today.setHours(0);
			today.setMinutes(0);
			today.setSeconds(0);
			console.log("inside filter");
			console.log(record.data.date);
			return record.data.date >= today; 
			}}
		],
		
		grouper: { groupFn: function(record) {
					
					var date = Ext.Date.format(record.get('date'),"F j, Y");
					var now = new Date();
					var tomorrow = new Date();
					tomorrow.setDate(now.getDate() +1);

					var nowformat = Ext.Date.format(now,"F j, Y");
					var tomorrowformat = Ext.Date.format(tomorrow,"F j, Y");
					
					if  (date.toString() == nowformat.toString()){
						return "Today";
					}
					else if (date.toString() == tomorrowformat.toString()) {
						return "Tomorrow";
					}
					else {
						var d = new Date(record.get('date'))
						var month = d.getMonth() + 1;
						var day = d.getDate();
						if (month <  9){
							month = "0" + month;
						}
						return " " + month + "." + day;
					}
					//return record.get('date').format("Y-m-d");
			},
			sortProperty: 'date'
		},
	
	}
		
	
});